package smedi.ismedi.web.bff.controller.inmail;

import com.smedi.ismedi.inmail.api.dto.request.QueryListTaskRecordRequest;
import com.smedi.ismedi.inmail.api.dto.request.QueryPageTaskRecordRequest;
import com.smedi.ismedi.inmail.api.dto.request.TaskRecordDeleteRequest;
import com.smedi.ismedi.inmail.api.dto.response.TaskRecordCountResponse;
import com.smedi.ismedi.inmail.api.dto.response.TaskRecordResponse;
import com.smedi.ismedi.inmail.api.feign.RemoteTaskFeignApi;
import com.smedi.ismedi.web.starter.common.PaginationData;
import com.smedi.ismedi.web.starter.common.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "任务接口")
@RequestMapping(value = "/webbff/v1/task")
@RestController
@AllArgsConstructor
public class TaskController {
    private final RemoteTaskFeignApi remoteTaskFeignApi;

    @ApiOperation(httpMethod = "GET", value = "任务统计")
    @GetMapping("/getTaskRecordCount")
    ResponseData<TaskRecordCountResponse> getTaskRecordCount(@RequestParam("personId") Long id) {
        return remoteTaskFeignApi.getTaskRecordCount(id);
    }

    @ApiOperation(httpMethod = "GET", value = "阅读任务")
    @GetMapping("/readTask")
    ResponseData<List<TaskRecordResponse>> postReadTask(@RequestParam("taskIds") List<Long> ids) {
        return remoteTaskFeignApi.postReadTask(ids);
    }

    @ApiOperation(httpMethod = "GET", value = "任务列表")
    @GetMapping("/queryListTaskRecord")
    ResponseData<List<TaskRecordResponse>> getQueryListTaskRecord(@Validated @SpringQueryMap QueryListTaskRecordRequest queryListTaskRecordRequest) {
        return remoteTaskFeignApi.getQueryListTaskRecord(queryListTaskRecordRequest);
    }

    @ApiOperation(httpMethod = "GET", value = "任务列表分页")
    @GetMapping("/queryPageTaskRecord")
    ResponseData<PaginationData<TaskRecordResponse>> getQueryPageTaskRecord(@Validated @SpringQueryMap QueryPageTaskRecordRequest queryPageTaskRecordRequest) {
        return remoteTaskFeignApi.getQueryPageTaskRecord(queryPageTaskRecordRequest);
    }

    @ApiOperation(httpMethod = "DELETE", value = "根据来源列表删除任务")
    @DeleteMapping("/deleteTask/sources")
    ResponseData<Boolean> postDeleteTaskBySources(@Validated @RequestBody List<TaskRecordDeleteRequest> taskRecordDeleteRequests) {
        return remoteTaskFeignApi.postDeleteTaskBySources(taskRecordDeleteRequests);
    }
}
